package com.hmall.api.client;

import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import com.hmall.api.fallback.ItemClientFallbackFactory;
import com.hmall.common.domain.PageDTO;
import com.hmall.common.utils.BeanUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * @author zhengsuyang
 * 2025.11.1
 */
@FeignClient(value = "item-service",path = "/items",fallbackFactory = ItemClientFallbackFactory.class)
public interface ItemClient {
    /**
     * 根据id批量查询商品
     * @param ids
     * @return
     */
    @GetMapping
    List<ItemDTO> queryItemByIds(@RequestParam("ids") Collection<Long> ids);

    /**
     * 根据id查询商品
     * @param id
     * @return
     */
    @ApiOperation("根据id查询商品")
    @GetMapping("{id}")
    public ItemDTO queryItemById(@PathVariable("id") Long id);

    @PutMapping("/stock/deduct")
    public void deductStock(@RequestBody List<OrderDetailDTO> items);

    /**
     * 恢复库存
     * @param item
     */
    @PutMapping
    public void updateItem(@RequestBody ItemDTO item);
    /**
     * 分页查询商品,给search微服务提供的
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/pageList")
    public List<ItemDTO> queryItemByPage( @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize")Integer pageSize);
}
